/**
 * 
 */
package neptune.manager.builder;

import java.util.BitSet;

import neptune.manager.model.topology.IPAddress;
import neptune.manager.utils.BitUtils;
import neptune.manager.utils.IllegalValueException;
import neptune.manager.utils.UnsignedByte;

/**
 * @author Roberto Bifulco [RobertoBifulco.it] [info@robertoBifulco.it]
 * 
 */
public class ExpSubnetTEST {

	private static int prefix = 20;

	public static void main(String[] args) throws Exception {
		IPAddress addr = new IPAddress(4, "10.0.240.0", "255.255.240.0");
		getNextSubnet(addr);
		
		UnsignedByte[] mask = IPAddress.toUnsignedBytes(addr
				.getSubnetMask());

		BitSet maskBits = BitUtils.getBitValue(mask);
		int experimentPrefixLenght = maskBits.cardinality();
		
		System.out.println(experimentPrefixLenght);

	}

	public static IPAddress getNextSubnet(IPAddress actualSubnet)
			throws IllegalValueException {
		BitSet addr = BitUtils.getBitValue(actualSubnet.getUnsignedBytes());
		BitUtils.incrementBits(addr, prefix, 32);

		String addrString = IPAddress.toAddressString(IPAddress
				.getAddressBytesFromBits(addr));

		return new IPAddress(4, addrString, actualSubnet.getSubnetMask());
	}
}
